<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加职位</title>
</head>
<body>
<div id="editPositionForm">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/position/editPosition.do"  id="dataForm" class="grayForm" method="post">
                <input type="hidden" name="id" value="${param.id }"/>
                <input type="hidden" name="uuid" id="uuid" value=""/>
                <table>
                    <tr>
                        <td ><label for="companyUUID">所属公司:</label></td>
                        <td style="line-height:20px;">
                          <c:if test="${param.id>0}">
                             <input type="text" name="companyName"  id="companyName" value="" readonly="readonly" style="background-color: #F0F0F0">
                             <input type="hidden" name="companyUUID"  id="companyUUID" value="" >
                          </c:if>
                          <c:if test="${param.id<1}">
                             <input type="hidden" name="companyName"  id="companyName" value="" >
	                         <select name="companyUUID" id="companyUUID"  class="select-box" curV="" required>
	                               <option value="">请选择</option>
	                         </select>
                          </c:if>
                           
                        </td>
                        <td ><label for="companyUUID">所属部门:</label></td>
                        <td style="line-height:20px;">
                           <c:if test="${param.id>0}">
                             <input type="text" name="deptName"  id="deptName" value="" readonly="readonly" style="background-color: #F0F0F0">
                             <input type="hidden" name="deptUUID"  id="deptUUID" value="" >
                          </c:if>
                          <c:if test="${param.id<1}">
                             <input type="hidden" name="deptName"  id="deptName" value="" >
                           <select name="deptUUID" id="deptUUID"  class="select-box" curV="" required>
                               <option value="">请选择</option>
                           </select>
                          </c:if>
                        </td>
                    </tr>
                    <tr>
                        <td><label for="positionName">职位名称:</label></td>
                        <td  style="line-height:20px;"><input type="text" name="positionName" id="positionName" /></td>
                        <td><label for="jobLevel">职位级别:</label></td>
                        <td style="line-height:20px;">
                            <input type="text" class="easyui-combobox" id="jobLevel" name="jobLevel" 
				                           data-options="
				                                prompt:'请选择',
				                                width:150,
				                                height:25,
				                                url:getBasePath()+'dictionary/getDictionaryList4comboBox.do?parentUUID=20180521230810958543563',    
								        	    valueField:'dicCode',
								        	    textField:'dicname',
								        	    required: true,
								        	    onSelect:function(record){
								        	    }
								        	    "/>
                    </tr>
                    <tr>
                        <td><label for="positionDesc">备注:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" name="positionDesc" id="positionDesc" style="width:462px;"/></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData"  />
                            <input type="button" value="关闭" name="close" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
        </div>
        <script type="text/javascript">
        var baseId = "#editPositionForm ";
        $(document).ready(function () {
        	//加载单位数据
        	loadCompanyList();
        	var id = new Number($(baseId+"input[name='id']").val());
        	if(id>0){
        		//加载表单数据
            	loadFormData(id+"");
        	}
        	
        	$("#editPositionForm input[name='close']").click(function () {
       		    $("#editDataFormArea").window("close");
       	    })
        	
        	//当改变选项后给companyName赋值，并出他的部门列表
        	$(baseId+"select[name='companyUUID']").change(function(){
        	    var companyName= $(baseId+"select[name='companyUUID'] option:selected").text();
        	    var companyUUID= $(baseId+"select[name='companyUUID'] option:selected").val();
        	    $(baseId+"input[name='companyName']").val(companyName)
        	    loadDeptList(companyUUID);
        	})
        	
        	//当改变选项后给companyName赋值，并出他的部门列表
        	$(baseId+"select[name='deptUUID']").change(function(){
        	    var deptName= $(baseId+"select[name='deptUUID'] option:selected").text();
        	    var deptUUID= $(baseId+"select[name='deptUUID'] option:selected").val();
        	    $(baseId+"input[name='deptName']").val(deptName);
        	})
        	
        	
        	var rules = {}
        	var messages = {}
        	messages = {
        		companyUUID:"请选择所属公司",
        		positionName:"请输入职位名字"
            };
        	
        	var validateForm = $(baseId+"#dataForm").validate({
                 debug:true,
                 rules:rules,
                 messages:messages
            });
        	
            //提交数据到服务器
            $(baseId+"input[name='submitData']").click(function () {
            	//提交表单进行验证
            	$(baseId+"#dataForm").submit();
                var validateFlag = validateForm.form();
                var actionUrl = $("#dataForm").attr("action");
            	var formData  = $("#dataForm").form2Json();
            	if(validateFlag){
            		$(baseId+"#dataForm").form('submit',{
            			//当提交时
            			onSubmit:function(param){
            			},
            			success:function(data){
            				// change the JSON string to javascript object 
            				var data = eval('(' + data + ')');
            				if(data.code=="00"){
              				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？',function(flag){
              					  if(flag){
              						  $("#editDataFormArea").window("close");
              						  tableObject.datagrid('reload');
              					  }
              				  });
              			    }else{
              				   $.messager.alert('操作提示',data.message,'error');
              			    }
            			}
            		});
            	}
            });
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"position/getJsonDetail.do",{id:id},function(jsonData){
        		$(baseId+" #dataForm").form("load",jsonData.data);
  		    },"json");
        }
        
        //加载单位数据
        function loadCompanyList(){
        	$.post(getBasePath()+"company/getJsonAllList.do",{},function(jsonData){
        		var optionList = "<option value=\"\">请选择</option>";
        		$.each(jsonData.data,function(i,item){
        			optionList+= "<option value=\""+item.uuid+"\">"+item.companyName+"</option>";
        		})
        		$(baseId+"select[name='companyUUID']").html(optionList);
  		    },"json");
        }
        
        //加载部门数据
        function loadDeptList(companyUUID){
        	$.post(getBasePath()+"department/getJsonAllList.do",{companyUUID:companyUUID},function(jsonData){
        		var optionList = "<option value=\"\">请选择</option>";
        		$.each(jsonData.data,function(i,item){
        			optionList+= "<option value=\""+item.uuid+"\">"+item.departmentName+"</option>";
        		})
        		$(baseId+"select[name='deptUUID']").html(optionList);
  		    },"json");
        }
    </script>
  </div>
</body>
</html>